//
//  CustomerServiceSystemTableViewCell.swift
//  ZNZXSuperMarket
//
//  Created by 四川中农 on 2018/8/8.
//  Copyright © 2018年 四川中农. All rights reserved.
//

import UIKit

class CustomerServiceSystemTableViewCell: UITableViewCell {
    
    @IBOutlet weak var bgView: UIView!
    @IBOutlet weak var questionContentView: UIView!
    @IBOutlet weak var contentViewHeight: NSLayoutConstraint!
    @IBOutlet weak var headerImg: UIImageView!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        self.bgView.setCornerRadio(radio: 22.5, isMask: false)
        self.updateQuestion()
        self.headerImg.setBorder(color: "000000", width: 0.5)
        self.headerImg.setCornerRadio(radio: 45 * 0.5, isMask: true)
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        // Configure the view for the selected state
    }
    
    func updateQuestion(){
        
        // 141
        let array = ["·如何进行店铺管理？","·如何进行店铺管理如何进行店铺管理如何进行店铺管理？","·如何进行店铺管理？","·如何进行店铺管理？"]
        var bottom:CGFloat = 0
        for i in 0 ..< array.count {
            let y = (i == 0 ? 0 : bottom)
            let height = array[i].rect(withFont: UIFont.systemFont(ofSize: 14), size: CGSize.init(width: UIScreen.ScreenWidth - 141, height: CGFloat.greatestFiniteMagnitude)).height + 3
            let label = Utils.labelWith(frame: CGRect.init(x: 0, y: Int(y), width: Int(UIScreen.ScreenWidth - 141), height: Int(height)), font: UIFont.systemFont(ofSize: 14), textAlignment: NSTextAlignment.left, textColor: "ffffff", text: array[i])
            label.numberOfLines = 0
            let attributedString = NSMutableAttributedString(string: array[i])
            attributedString.addAttributes([
                NSAttributedStringKey.underlineStyle:NSNumber.init(value: NSUnderlineStyle.styleSingle.rawValue)
                ], range: NSRange(location: 1, length: array[i].count - 2))
            label.attributedText = attributedString
            self.questionContentView.addSubview(label)
            if i == array.count - 1 {
                bottom = label.bottom
            }else {
                bottom = label.bottom + 14
            }
            self.contentViewHeight.constant = bottom
        }
        
    }

}
